/**
 * Created by Administrator on 2017/3/13 0013.
 */
Page1={
    Create:function(){
        var page={};
        var bigWhole=new PIXI.DisplayObjectContainer();
        var whole=new PIXI.DisplayObjectContainer();

        var whiteBG=new PIXI.Graphics();
        whiteBG.beginFill(0xffffff,1);
        whiteBG.drawRect(0,0,740,1136);


        var hitSound=document.getElementById("JaudioHit");
        var hitSound2=document.getElementById("JaudioHit2");
        var hitSound3=document.getElementById("JaudioHit3");
        // hitSound.load();


      // alert('123123');



        var bg =PSP("page1_6");
        var sir=PSP("page1_99");
        var title1=PSP("page1_2");
        var title2=PSP("page1_3");
        var title3=PSP("page1_4");
        var pink=PSP("page1_5");
        var logo=PSP("page1_7");
        var wordRed1=PSP("page1_8");
        var wordRed2=PSP("page1_9");
        var wordRed3=PSP("page1_10");
        var wordBlack1=PSP("page1_11");
        var wordBlack2=PSP("page1_12");
        var wordBlack3=PSP("page1_13");
        var wordBlack4=PSP("page1_14");
        var wordBlack5=PSP("page1_15");
        var wordBlack6=PSP("page1_16");
        var wordBlack7=PSP("page1_17");
        var frame=PSP("page1_18");

        var StartWord=PSP("page1_24");
        var StartMRUp=PSP("page1_22");
        var StartMRDown=PSP("page1_23");


        sir.x=478;sir.y=544;
        title1.x=326;title1.y=336;
        title2.x=325;title2.y=426;
        title3.x=662;title3.y=335;
        pink.x=0;pink.y=0;
        logo.x=582;logo.y=44;
        wordRed1.x=205;wordRed1.y=0;
        wordRed2.x=205;wordRed2.y=171;
        wordRed3.x=205;wordRed3.y=316;
        wordBlack1.x=0;wordBlack1.y=0;
        wordBlack2.x=0;wordBlack2.y=144;
        wordBlack3.x=0;wordBlack3.y=254;
        wordBlack4.x=0;wordBlack4.y=562;
        wordBlack5.x=0;wordBlack5.y=703;
        wordBlack6.x=0;wordBlack6.y=849;
        wordBlack7.x=0;wordBlack7.y=994;
        frame.x=155;frame.y=20;
        StartWord.x=0;StartWord.y=0;
        StartMRUp.x=0;StartMRUp.y=0;
        StartMRDown.x=0;StartMRDown.y=0;



        whole.addChild(whiteBG);
        whole.addChild(bg);
        whole.addChild(pink);
        whole.addChild(sir);
        whole.addChild(title1);
        whole.addChild(title2);
        whole.addChild(title3);
        whole.addChild(wordRed1);
        whole.addChild(wordRed2);
        whole.addChild(wordRed3);
        whole.addChild(wordBlack1);
        whole.addChild(wordBlack2);
        whole.addChild(wordBlack3);
        whole.addChild(wordBlack4);
        whole.addChild(wordBlack5);
        whole.addChild(wordBlack6);
        whole.addChild(wordBlack7);
        whole.addChild(frame);
        whole.addChild(logo);



        pink.alpha=0;
        // sir.alpha=0;
        title1.alpha=0;
        title2.alpha=0;
        title3.alpha=0;
        wordRed1.alpha=0;
        wordRed2.alpha=0;
        wordRed3.alpha=0;
        wordBlack1.alpha=0;
        wordBlack2.alpha=0;
        wordBlack3.alpha=0;
        wordBlack4.alpha=0;
        wordBlack5.alpha=0;
        wordBlack6.alpha=0;
        wordBlack7.alpha=0;
        frame.alpha=0;
        logo.alpha=0;




        var bgMask=new PIXI.Graphics();
        bgMask.beginFill(0x000000,1);
        bgMask.drawCircle(0,0,500);
        whole.addChild(bgMask);
        bgMask.x=205;bgMask.y=316;
        bg.mask=bgMask;
        bgMask.scale.set(0);

        var pinkMask=new PIXI.Graphics();
        pinkMask.beginFill(0x000000,1);
        pinkMask.drawRect(0,0,740,1136);
        whole.addChild(pinkMask);
        pink.mask=pinkMask;
        pinkMask.x=591;pinkMask.y=0;




        var blackBGL=new PIXI.Graphics();
        blackBGL.beginFill(0x000000,1);
        blackBGL.drawRect(0,0,370,1136);
        var blackBGR=new PIXI.Graphics();
        blackBGR.beginFill(0x000000,1);
        blackBGR.drawRect(370,0,370,1136);



        var StartWordMask=new PIXI.Graphics();
        StartWordMask.beginFill(0xff0000,1);
        StartWordMask.drawRect(0,0,1000,350);
        StartWord.mask=StartWordMask;

        var StartMRUpMask=new PIXI.Graphics();
        StartMRUpMask.beginFill(0xff0000,1);
        StartMRUpMask.drawRect(0,0,740,177);
        StartMRUp.mask=StartMRUpMask;
        var StartMRDownMask=new PIXI.Graphics();
        StartMRDownMask.beginFill(0xff0000,1);
        StartMRDownMask.drawRect(0,0,740,150);
        StartMRDown.mask=StartMRDownMask;


        bigWhole.addChild(whole);
        bigWhole.addChild(blackBGL);
        bigWhole.addChild(blackBGR);
        bigWhole.addChild(StartWordMask);
        bigWhole.addChild(StartMRUpMask);
        bigWhole.addChild(StartMRDownMask);
        bigWhole.addChild(StartWord);
        bigWhole.addChild(StartMRUp);
        bigWhole.addChild(StartMRDown);

        //调试用
        page.Debug=function(){
            bigWhole.removeChild(whiteBG);
            bigWhole.removeChild(blackBGL);
            bigWhole.removeChild(blackBGR);
            bigWhole.removeChild(StartWordMask);
            bigWhole.removeChild(StartWord);
            bigWhole.removeChild(StartMRUp);
            bigWhole.removeChild(StartMRDown);
            bigWhole.removeChild(StartWordMask);
            bigWhole.removeChild(StartMRUpMask);
            bigWhole.removeChild(StartMRDownMask);
            pink.blendMode = PIXI.BLEND_MODES.MULTIPLY;
            bg.alpha=1;
            pink.alpha=1;
            pinkMask.x=0;

            bgMask.scale.set(2);
            title1.alpha=1;
            title2.alpha=1;
            title3.alpha=1;
            wordRed1.alpha=1;
            wordRed2.alpha=1;
            wordRed3.alpha=1;
            wordBlack1.alpha=1;
            wordBlack2.alpha=1;
            wordBlack3.alpha=1;
            wordBlack4.alpha=1;
            wordBlack5.alpha=1;
            wordBlack6.alpha=1;
            wordBlack7.alpha=1;
            frame.alpha=1;
            logo.alpha=1;
        };


        //开始！
        var sirShakeTimes = 0;
        function sirMove(time){
            sirShakeTimes++;
            TweenMax.to(sir,0.001,{delay:time,x:sir.x+24*sirShakeTimes,y:sir.y+26*sirShakeTimes});
        }

        var bala=0;
        function Shake(time){

            setTimeout(function(){
                bala++;
                if(bala%3==0){
                    hitSound2.currentTime=0;
                    hitSound2.play();
                    console.log("0")
                }
                else if(bala%3==1){
                    hitSound.currentTime=0;
                    hitSound.play();
                    console.log("1")
                }
                else{
                    hitSound3.currentTime=0;
                    hitSound3.play();
                    console.log("2")
                }

            },time*1000-150)




            TweenMax.to(whole,0.02,{delay:time,x:10,y:4});
            TweenMax.to(whole,0.02,{delay:time+0.02,x:-8,y:-8});
            TweenMax.to(whole,0.02,{delay:time+0.04,x:6,y:8});
            TweenMax.to(whole,0.02,{delay:time+0.06,x:-4,y:5});
            TweenMax.to(whole,0.02,{delay:time+0.08,x:0,y:0});
        }

        page.End=function(){
            whole.addChild(title1);
            whole.addChild(title2);
            whole.addChild(title3);
            whole.addChild(wordRed1);
            whole.addChild(wordRed2);
            whole.addChild(wordRed3);
            whole.addChild(wordBlack1);
            whole.addChild(wordBlack2);
            whole.addChild(wordBlack3);
            whole.addChild(wordBlack4);
            whole.addChild(wordBlack5);
            whole.addChild(wordBlack6);
            whole.addChild(wordBlack7);
            whole.addChild(frame);
            whole.addChild(logo);
            var aTime=0;

            TweenMax.to(frame,1,{delay:0.1*aTime,x:750,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(logo,1,{delay:0.1*aTime,x:750,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(title1,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(title2,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(title3,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordRed1,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordRed2,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordRed3,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack1,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack2,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack3,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack4,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack5,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack6,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(wordBlack7,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(bg,1,{delay:0.1*aTime,alpha:0,ease:Cubic.easeOut});
            aTime++;
            TweenMax.to(pinkMask,1,{delay:0.1*aTime,x:750,ease:Cubic.easeOut});
            aTime++;














            sir.anchor.set(0.5);
            TweenMax.to(sir,0.7,{delay:2.5,x:305+129/2,y:718+266/2,ease:Cubic.easeOut});
            TweenMax.to(sir,0.7,{delay:2.5,width:100,height:344,x:305+129/2,y:718+90,ease:Cubic.easeOut});

            TweenMax.to(sir.skew,0.7,{delay:3,x:-0.57,y:-1,ease:Cubic.easeOut});
            TweenMax.to(sir,0.7,{delay:3,rotation:Math.PI/180*-30,ease:Cubic.easeOut});

        };
        page.start=function() {
            setTimeout(function(){
                whole.interactive=true;
            },18600);




            StartWordMask.x = -1000;
            StartWordMask.y = 800;

            TweenMax.to(StartWordMask, 1.5, {delay: 0.5, x: 740, ease: Cubic.easeOut});
            TweenMax.to(StartWordMask, 0.01, {delay: 2.0, y: 0, x: 740, ease: Cubic.easeOut});
            TweenMax.to(StartWordMask, 1.5, {delay: 2.01, x: -1000, ease: Cubic.easeOut});
            TweenMax.to(StartWordMask.scale, 0.01, {delay: 3.51, x: 0, y: 0, ease: Cubic.easeOut});

            StartMRUpMask.x = -1000;
            StartMRUpMask.y = 400;
            StartMRDownMask.x = 740;
            StartMRDownMask.y = 576;

            TweenMax.to(StartMRUpMask, 1.5, {delay: 3.51, x: 0, ease: Back.easeOut});
            TweenMax.to(StartMRDownMask, 1.5, {delay: 3.51, x: 0, ease: Back.easeOut});

            TweenMax.to(StartMRUpMask, 1.0, {delay: 5.1, x: 740, ease: Cubic.easeInOut});
            TweenMax.to(StartMRDownMask, 1.0, {delay: 5.1, x: -740, ease: Cubic.easeInOut});

            TweenMax.to(blackBGL, 0.6, {delay: 5.53, x: -370, ease: Cubic.easeOut});
            TweenMax.to(blackBGR, 0.6, {delay: 5.53, x: 370, ease: Cubic.easeOut});


            sir.x = pixiStageW / 2;
            sir.y = pixiStageH / 2;
            sir.anchor.set(0.5);

            wordRed1.anchor.set(0.5);
            wordRed1.scale.set(0.1);
            wordRed2.anchor.set(0.5);
            wordRed2.scale.set(0.1);
            wordRed3.scale.set(0.1);

            wordRed1.x = 551;
            wordRed1.y = 319;
            wordRed1.rotation = Math.PI / 180 * -63;

            TweenMax.to(wordRed1, 1, {
                delay: 6.3,
                alpha: 1,
                x: 700,
                y: 281,
                rotation: Math.PI / 180 * -38,
                ease: Cubic.easeInOut
            });
            TweenMax.to(wordRed1.scale, 1, {delay: 6.3, x: 1.6, y: 1.6});
            TweenMax.to(wordRed1, 0.4, {
                delay: 7.3,
                alpha: 1,
                x: 205 + 166 / 2,
                y: 148 / 2,
                rotation: 0,
                ease: Cubic.easeIn
            });
            TweenMax.to(wordRed1.scale, 0.4, {delay: 7.3, x: 1, y: 1});

            Shake(7.7);

            wordRed2.x = 551;
            wordRed2.y = 359;
            wordRed1.rotation = Math.PI / 180 * -53;

            TweenMax.to(wordRed2, 1, {
                delay: 7.0,
                alpha: 1,
                x: 700,
                y: 261,
                rotation: Math.PI / 180 * -38,
                ease: Cubic.easeInOut
            });
            TweenMax.to(wordRed2.scale, 1, {delay: 7.0, x: 1.6, y: 1.6});
            TweenMax.to(wordRed2, 0.4, {
                delay: 8.0,
                alpha: 1,
                x: 205 + 166 / 2,
                y: 148 / 2 + 171,
                rotation: 0,
                ease: Cubic.easeIn
            });
            TweenMax.to(wordRed2.scale, 0.4, {delay: 8.0, x: 1, y: 1});

            Shake(8.4);

            wordRed3.x = 551;
            wordRed3.y = 359;
            wordRed1.rotation = Math.PI / 180 * -53;

            TweenMax.to(wordRed3, 1, {
                delay: 12.0,
                alpha: 1,
                x: 500,
                y: 261,
                rotation: Math.PI / 180 * -38,
                ease: Cubic.easeInOut
            });
            TweenMax.to(wordRed3.scale, 1, {delay: 12.0, x: 10, y: 10});
            TweenMax.to(wordRed3, 0.4, {delay: 12.4, alpha: 1, x: 205, y: 316, rotation: 0, ease: Cubic.easeIn});
            TweenMax.to(wordRed3.scale, 0.4, {delay: 12.4, x: 1, y: 1});

            Shake(12.8);
            //最后出场处理
            bg.alpha = 1;
            pink.alpha = 1;
            TweenMax.to(bgMask.scale, 1, {delay: 12.8, x: 2, y: 2, ease: Cubic.easeOut});
            title1.x -= 100;
            TweenMax.to(title1, 0.7, {delay: 13.2, alpha: 1, x: title1.x + 100, ease: Cubic.easeInOut});
            title2.x += 75;
            TweenMax.to(title2, 0.7, {delay: 13.9, alpha: 13.5, x: title2.x - 75, ease: Cubic.easeInOut});
            title3.scale.set(0);
            title3.anchor.set(0.5, 1);
            TweenMax.to(title3, 0.7, {delay: 14.5, alpha: 1, x: title3.x + 10, y: title3.y + 40, ease: Cubic.easeOut});
            TweenMax.to(title3.scale, 0.7, {delay: 14.5, x: 4, y: 4});
            TweenMax.to(title3, 0.4, {
                delay: 15.2,
                alpha: 1,
                x: title3.x + 12,
                y: title3.y + 140,
                ease: Cubic.easeInOut
            });
            TweenMax.to(title3.scale, 0.4, {delay: 15.2, x: 1, y: 1});
            TweenMax.to(pinkMask, 1, {delay: 15.6, x: 0, ease: Cubic.easeOut});
            Shake(15.6);


            //
            pink.blendMode = PIXI.BLEND_MODES.MULTIPLY;


            TweenMax.to(title3, 1.3, {
                delay: 17,
                yoyo: true,
                repeat: -1,
                rotation: Math.PI / 180 * 10,
                ease: Back.easeInOut
            });
            frame.x = frame.x + 15;
            TweenMax.to(frame, 1, {delay: 16.5, alpha: 1, x: frame.x - 15, ease: Cubic.easeOut});

            logo.x = logo.x - 20;
            TweenMax.to(logo, 1, {delay: 17, alpha: 1, x: logo.x + 20, ease: Cubic.easeOut});
            TweenMax.to(logo, 0.7, {delay: 18, yoyo: true, repeat: -1, alpha: 0.5});
            TweenMax.to(pink, 2, {delay: 18, yoyo: true, repeat: -1, alpha: 0.9});


            sirMove(7.7);
            sirMove(8.4);


            arrBW = [wordBlack1, wordBlack2, wordBlack3, wordBlack4, wordBlack5, wordBlack6, wordBlack7];
            for (var z = 0; z < arrBW.length; z++) {
                var w = arrBW[z].width;
                var h = arrBW[z].height;
                var x = arrBW[z].x;
                var y = arrBW[z].y;
                arrBW[z].anchor.set(0.5);
                arrBW[z].scale.set(0.1);

                arrBW[z].x = 521 + Math.random() * 30;
                wordBlack1.y = 330 + 10 * z;
                wordBlack1.rotation = Math.PI / 180 * (-63 + Math.random() * 20);

                var wordBlackTime = 7.7 + (0.5 - z * 0.03) * z;
                TweenMax.to(arrBW[z], 1, {
                    delay: wordBlackTime,
                    alpha: 1,
                    x: 700,
                    y: 261 + 10 * z,
                    rotation: Math.PI / 180 * -38,
                    ease: Cubic.easeInOut
                });
                TweenMax.to(arrBW[z].scale, 1, {delay: wordBlackTime, x: 1.6, y: 1.6});
                TweenMax.to(arrBW[z], 0.4, {
                    delay: wordBlackTime + 1,
                    alpha: 1,
                    x: w / 2,
                    y: y + h / 2,
                    rotation: 0,
                    ease: Cubic.easeIn
                });
                TweenMax.to(arrBW[z].scale, 0.4, {delay: wordBlackTime + 1, x: 1, y: 1});
                Shake(wordBlackTime + 1.4);

                sirMove(wordBlackTime + 1.4);
            }


        }


        whole.on("pointerdown",function(){
            whole.interactive=false;
            document.dispatchEvent(new CustomEvent("PageChange",{detail:2}));
        })





        page.ReturnWhole=function(){
            return bigWhole;
        };

        return page;
    }
}
